package com.lc.user.express.httpserver;

import android.text.TextUtils;

import com.lc.user.express.model.DriverModel;
import com.lc.user.express.utils.PublicMethod;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/11.选择司机列表
 */
@HttpInlet(Net.GET_CHOOSE_DRIVERINFO)
public class GetChooseDriverInfo extends ZJDBAsyGet<GetChooseDriverInfo.Info> {

    public String orderid;//订单id
    public String userid;

    public GetChooseDriverInfo(String userid, String orderid, AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
        this.orderid = orderid;
        this.userid = userid;

    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            JSONArray array = object.optJSONArray("list");
            if (array != null) {
                for (int i = 0; i < array.length(); i++) {
                    JSONObject object1 = array.optJSONObject(i);
                    DriverModel model = new DriverModel();
                    model.setDriverId(object1.optString("driverid"));
                    model.setPicUrl(object1.optString("avatar"));
                    model.setName(object1.optString("name"));
                    model.setStar(object1.optString("star"));
                    model.setIsfreemove(object1.optInt("isfreemove"));
                    model.setPoint(object1.optString("point"));
                    model.setNumber(object1.optString("number"));
                    if(!TextUtils.isEmpty(object1.optString("point"))){
                        String[] s = object1.optString("point").split(",");
                        model.setLng(PublicMethod.strToDouble(s[1]));
                        model.setLat(PublicMethod.strToDouble(s[0]));
                    }
                    info.list.add(model);

                }
                return info;
            }
        }
        return null;
    }

    public static class Info {
        public List<DriverModel> list = new ArrayList<>();
    }
}
